package com.fxkj.html2docx;

import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * HTML 转换 Word
 *
 * @author Lsd 2018-01-19
 */
public class HTML2Word {
    public static void main(String[] args) throws Exception {

        String filepath = "C:/test/";
        //创建 POIFSFileSystem 对象
        POIFSFileSystem poifs = new POIFSFileSystem();
        //获取DirectoryEntry
        DirectoryEntry directory = poifs.getRoot();
        //创建输出流
        OutputStream out = new FileOutputStream(filepath + "2003.doc");
        //创建文档,1.格式,2.HTML文件输入流
        InputStream is = new FileInputStream(filepath + "2003.html");
        directory.createDocument("WordDocument", is);
        //写入
        poifs.writeFilesystem(out);
        //释放资源
        out.close();
        System.out.println("success");
    }


}
